package com.itheima.controller;

import com.itheima.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class HttpSessionTest2 {
    @Autowired
    private HttpSession session;
    //会话对象，就像一个Map集合可以保存数据，浏览器每次简历会话都有一个Session对象

    @GetMapping("/loginTest2")
    public Result loginTest1() {
        Boolean isLogin = (Boolean) session.getAttribute("isLogin");
        if (isLogin == null || isLogin == false) {
            return Result.error("未登录，不能访问资源");
        } else {
            return Result.success("登录成功，可以访问资源");
        }

    }




}
